package com.wc.算法基础课.A第一讲基础算法.区间合并.管道;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/12 15:29
 * @description https://www.acwing.com/problem/content/5410/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] l = new int[N];
    static int[] s = new int[N];
    static long[][] a = new long[N][2];
    static int lenA = 0;
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            l[i] = sc.nextInt();
            s[i] = sc.nextInt();
        }
        long l = 1;
        long r = (int) 2e9;
        while (l < r) {
            long mid = l + r >> 1;
            if (check(mid)) {
                r = mid;
            } else l = mid + 1;
        }
        out.println(l);
        out.flush();
    }

    static boolean check(long mid) {
        lenA = 0;
        for (int i = 1; i <= n; i++) {
            if (mid >= s[i]) {
                long left = Math.max(1, l[i] - (mid - s[i]));
                long right = Math.min(m, (long) l[i] + (mid - s[i]));
                a[++lenA][0] = left;
                a[lenA][1] = right;
            }
        }
        Arrays.sort(a, 1, lenA + 1, ((o1, o2) -> {
            if (o1[0] == o2[0]) {
                if (o1[1] > o2[1]) return 1;
                else return 0;
            }
            if (o1[0] > o2[0]) return 1;
            return -1;
        }));
        long st = 0;
        long ed = -1;
        for (int i = 1; i <= lenA; i++) {
            if (ed + 1 < a[i][0]) {
                st = a[i][0];
            }
            ed = Math.max(a[i][1], ed);
        }
        return st == 1 && ed == m;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}